import socket

def main():
    # 创建 socket 
    server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    # 绑定并监听客户端发送消息
    server.bind(("localhost", 8888))
    server.listen(128)

    print("---------%s---------" % "等待客户端连接")

    # 等待客户端连接
    client_socket, client_addr = server.accept()

    # 接受客户端发送过来的数据
    recv_data = client_socket.recvfrom(1024)

    # 打印接收到的数据
    print(recv_data[0].decode("utf-8"))

    # 给客户端相应数据
    client_socket.send("think you!".encode("utf-8"))

    # 关闭 socket
    server.close()

if __name__ == '__main__':
    main()